﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Job.Data.Interfaces;
using Job.Web.Framework;
using System.Collections;

namespace Job.Data
{
    public class Common:BaseSqlMapDao,ICommon
    {
        #region ICommon Members

        public string GetServerTime()
        {
            try
            {
                return ExecuteQueryForObject<string>(DBObjectNames.GetServerTime, null);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message);
                return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            }
        }

        public System.Data.DataSet GetPageData(System.Data.IDataParameter[] Params)
        {
            try
            {
                return QueryForDataSetParams(DBObjectNames.GetPageData, Params);
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message);
                return null;
            }
        }

        public bool Login(string username, string password)
        {
            Hashtable ht = new Hashtable();
            ht.Add("user_name", username);
            ht.Add("password", password);
            bool result = false;
            try
            {
                object obj = ExecuteQueryForObject(DBObjectNames.Login, ht);
                if (obj != null && Convert.ToInt32(obj) == 1)
                {
                    result = true;
                }
            }
            catch (Exception ex)
            {
                Logger.WriteLog(ex.Message);
                return false;
            }

            return result;
        }
        #endregion
    }
}
